<template>
  <div>
    <router-view></router-view>
    <el-input v-model="name" placeholder="请输入用户名"></el-input>
    <el-button type="primary" @click="login()">登录</el-button>
  </div>
</template>
<script>
import axios from "axios";
import { addServerRoutes, resetRouter } from "@/router/example2";
const options = {
  data() {
    return {
      name: "admin",
    };
  },
  methods: {
    async login() {
      //登录后充值路由
      resetRouter();
      const resp = await axios.get("/api/menu/" + this.name);
      console.log(this.$router.getRoutes());
      // localStorage     即使浏览器关闭，存储的数据仍在
      // sessionStorage   以标签页为单位，关闭标签页时，数据被清除
      //将路由信息存入  sessionStorage，当刷新页面，路由信息仍然存在
      sessionStorage.setItem('serverRoutes',JSON.stringify(resp.data))
      addServerRoutes(resp.data);
      console.log(this.$router.getRoutes());
      this.$router.push('/')
    },
  },
};
export default options;
</script>@/router/example2